#include <config.h>

#include <gtkmm.h>
using sigc::mem_fun;
using sigc::ptr_fun;
#include <glibmm/i18n.h>

#include <process_struct.h>
#include <configuration.h>
#include <system_monitor.h>
#include <appmenu_updater.h>
#include <notification_sender.h>

int main(int argc, char *argv[])
{
    Gtk::Main kit (argc, argv);

    /* initialize gettext */
    bindtextdomain(GETTEXT_PACKAGE, PROGRAMNAME_LOCALEDIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);

    /* configuration file */
    configuration config (
            Glib::get_user_config_dir() + "/" + PACKAGE_NAME);

    /* monitor system loads */
    system_monitor monitor(config);

    /* application indicator */
    appmenu_updater indicator(config);

    /* activate NofifyOSD when a bad process appears */
    notification_sender notifier(config);

	/* connect monitor and indicator */
    monitor.signal_add_process.connect (
        mem_fun (indicator, &appmenu_updater::process_added));
    monitor.signal_add_process.connect (
        mem_fun (notifier, &notification_sender::process_added));
    monitor.signal_remove_process.connect (
        mem_fun (indicator, &appmenu_updater::process_removed));
    monitor.signal_update_process.connect (
        mem_fun (indicator, &appmenu_updater::process_updated));
    monitor.signal_sys_update.connect (
        mem_fun (indicator, &appmenu_updater::sys_update));

    /* save configuration at exit */
    kit.signal_quit ().connect (
            mem_fun (config, &configuration::save));

    kit.run ();
}
